// pages/dishes_report/dishes_report.js
const app = getApp()
const getdata = require("../../tool/GetDate.js");
const util = require("../../utils/util.js");
var currentPage = 0;
var listData = [];
var paramData = [];

Page({

  /**
   * 页面的初始数据
   */
  data: {
    dishesReportList: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    currentPage = 1;
    listData = [];
    let param = {};
    param.hallID = 1;
    param.startDate = util.formatDateDiff(-7);
    param.endDate = util.formatDate(new Date);
    param.currentPage = currentPage;
    param.districtID = app.globalData.myUserData.districtID;
    paramData = param;
    this.getDishesReport(JSON.stringify(param));
  },

  getDishesReport: function (data) {
    let that = this;
    getdata.postdata({
      url: "gbt/Dishes/DishesReport",
      data: data,
      success: function (res) {
        console.log(res.root);
        if (res.root) {
          let array = res.root.data;
          let dishesReportItem = {};
          for (let index = 0; index < array.length; index++) {
            dishesReportItem.title = array[index].dishesName;
            dishesReportItem.hallName = array[index].dishesNumber;
            dishesReportItem.mealDateTitle = "菜品类别";
            dishesReportItem.mealDateValue = array[index].className;
            dishesReportItem.mealTitle = "食堂";
            dishesReportItem.mealValue = array[index].HallName;
            dishesReportItem.amount = array[index].total;
            dishesReportItem.currency = ""
            listData.push(dishesReportItem);
            dishesReportItem = {};
          }
          console.log(listData);
          that.setData({
            dishesReportList: listData,
          });
        }
      }
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    currentPage++;
    paramData.currentPage = currentPage;
    let data = JSON.stringify(paramData);
    this.getDishesReport(data);
  },

  // /**
  //  * 用户点击右上角分享
  //  */
  // onShareAppMessage: function () {

  // },

  onDef:function(e){
    paramData = JSON.parse(e.detail);
    listData = [];
    this.getDishesReport(e.detail);
  },

  onConfirm:function(e){
    paramData = JSON.parse(e.detail);
    listData = [];
    this.getDishesReport(e.detail);
  },

})